package com.ruoyi.common.utils;


import com.icbc.api.IcbcApiException;
import com.icbc.api.utils.IcbcEncrypt;
import com.icbc.api.utils.IcbcSignature;

public class TestSignAndAES {

	//银行公钥
	private static String icbc_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzbiEx5q7frtbnJ+Prm5ZmsMvhjl5PL9OwbPcFBJPsLrFMGdf9/+mRmgoatwQ+iIhYF4BFDrJbDxjFHmyn28s5Dz/4iXFSLOLeyiRUtqcDPr8Z4rKQhiBQoxH28k0o09hrjkrbaPWAq9V+m+10JXde1G3pgcoLHujXycFku8fHjMuM61ZPKjZbNV5eXzxCfsynka/uDMXT3gUu4AwUO0yS8aHhpiHNXcevURbFmGCtEiFN95JceMRAumrwSIF2EKaBVJnQGSvGT2nX8YMfinktPgoAo1Baa3me6hMVmtCx6gHc6oUvKWg+Ik4B0OseAQo2fQVf5rVlV/AXaZK1WkwwIDAQAB";
	//合作方私钥
	private static String mer_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCvue6taEhlsPXGfQ0+LnnpyAYw8AD2ePPKNTYzmB/UuOQf5iEW2/g2bCnvMJzjSKMvwGH/11ntT9Xy8PALLPN/VMUtNNLT7LCNIJVHvir3l1Z0uNxXgmMqonbLPjcTl5E+VgwXPaGGMUNyPAvqAe1XeD64IHfYOLA2dkH0/YIcc1F+ToqgizR91DsByDMNXg+xrbO4qbV9C3fbrxlIvFl/3eOcRwPG1E2wO9FleeDd4c3YymVLmRHEd3902tdPMpYjo/iHHlPTF2WbIuHo82YwDZbOmDGltoVpFM92W8U1wqGRAZf75/ptDQCylYzqIz8IGP57BAlIkAcQ4uRad8MnAgMBAAECggEBAK3r+K7oZ78+RgMOAe1pUoBv2LDW2h0X2TJpOBwYlGiWFjL8MgPN8vzqURbLpnvNiLXaUyREoFygh8DLdsmY0+dSn1T+0yutN5B2j0lSjnQ+9PLRhEOYaU3pPmoqSZi6iqaHw6+88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作方AES
	private static String AESKey = "0Hr2Hd5RPp0bBnKx+LNqqw==";
	private static String encrypt_type = "AES";
	private static String sign_type = "RSA2";
	private static String charset = "UTF-8";

	public static void main(String[] args) {
		try {
			/**
			 * 工行请求合作方H5
			 */
			//请求合作方H5地址
//			String url = "https://localhost/test?param=加密后的参数&sign=签名数据";

			//合作方收到数据后在服务端进行验签
//			YGtAPVzxq0ugErnFYJR/nUAiYw94hPTvZMM vILtjSsonHeJxPGWH5u9RW/HvhU31wB6DCRqiFnaRAUXjeaRGCF4hXFUAmhP7T8KoAlU62U=
//					QI5qvbWMZMjbxbq4AFClBMafD5WBPDcWMtLdFe/yMWpVQQXqYAQVhxaZPR6rg6jlrW65twpMcjtScI6lfbSf2g3up 5BJ6FMQTzJOFvLdF7WWQSRCRms0Bp cICa/9PRaaGanywScMDgkqTEHMnGGwiYQsHxcJ08s8oZ6Piju18DSWQxwBXEITDZYzARX8b4axukjR91K2jvnhvFDVbFCbldsWfr3rsTOcHzn96DlfHNyFa90gPRgid8a Y9FmgsuhcBGKF85pqa yjkLaS49vC5YjUesVIfxe4187 EJ37pLZu9eSoeTx1HbTbXe4OCqEG/CW7sresLy4UcPVeBug==
			String param = "YGtAPVzxq0ugErnFYJR/nUAiYw94hPTvZMM+vILtjSsonHeJxPGWH5u9RW/HvhU31wB6DCRqiFnaRAUXjeaRGCF4hXFUAmhP7T8KoAlU62U=";
			String sign = "QI5qvbWMZMjbxbq4AFClBMafD5WBPDcWMtLdFe/yMWpVQQXqYAQVhxaZPR6rg6jlrW65twpMcjtScI6lfbSf2g3up+5BJ6FMQTzJOFvLdF7WWQSRCRms0Bp+cICa/9PRaaGanywScMDgkqTEHMnGGwiYQsHxcJ08s8oZ6Piju18DSWQxwBXEITDZYzARX8b4axukjR91K2jvnhvFDVbFCbldsWfr3rsTOcHzn96DlfHNyFa90gPRgid8a+Y9FmgsuhcBGKF85pqa+yjkLaS49vC5YjUesVIfxe4187+EJ37pLZu9eSoeTx1HbTbXe4OCqEG/CW7sresLy4UcPVeBug==";
			boolean flag = isFlag(param,sign);
			System.out.println("flag:" + flag);  //true表示通过

			//验签通过后AES解密数据
			String decrypt = IcbcEncrypt.decryptContent(param, encrypt_type, AESKey, charset);
			System.out.println("decrypt" + decrypt);

		} catch (IcbcApiException e) {
			e.printStackTrace();
		}
	}
	public static  boolean isFlag(String param,String sign) throws IcbcApiException {
		boolean flag = IcbcSignature.verify(param, sign_type, icbc_public_key, charset, sign);
		return flag;
	}

}
